define(["jquery","bootstrap","bbcare",
    "scprit/followup/app/prematureOvarianFailure/lifeEventScale.servers.js",
    "scprit/followup/app/prematureOvarianFailure/prematureOvarianFailureDetail.ui.js"],function($,bootstrap,$bb,$servers,$ui){
    var event = {};

    var pageTurnFn = function(question,scoreObj,dom,length){
        var group = $(dom).attr("group");
        var nowQuesId = $("#wrap_left_panel").find(".panel-heading").attr("id");
        var nextId = nowQuesId;
        if(group == "prev"){//上一题：
            if(nowQuesId*1 > 1){
                nextId =  nowQuesId -1;
            }else{
                $bb.toastShow("目前已经是第一题",2000);
            }
        }else if(group == "next"){//下一题：
            if(nowQuesId*1 < length*1){
                nextId =  nowQuesId*1 +1;
            }else{
                $bb.toastShow("目前已经是最后一题",2000);
            }
        }
        var nextListId = question[nextId].initId;
        $("#item-list li[initId='"+nextListId+"']").addClass("checked").siblings().removeClass("checked");
        $servers.lesAnswerDeal(question,nextId,scoreObj);
        $ui.questionsLesInit({"id":"#wrap_left_panel","data":question[nextId]});
    };
    event.init = function(questions,scoreObj,length){
        /*
         * 上一题、下一题
         * */
        $(".ques-tab").find("button").click(function(){
            var _this = this;
            pageTurnFn(questions,scoreObj,_this,length);
        });

        /*
        * 右侧列表点击事件：
        * */
        $("#item-list").on("click","li",function(){
            $(this).addClass("checked").siblings().removeClass("checked");
            var initId = $(this).attr("initId");
            $servers.lesAnswerDeal(questions,initId,scoreObj);
            $ui.questionsLesInit({"id":"#wrap_left_panel","data":questions[initId]});
        });
        $("#item-list li").eq(0).click();
        /*
        * 点击查看备注：
        * */
        $("#wrap_left_panel").on("click",".ques-mark",function(){
            var fuId = $(this).attr("fuId");
            var childId = $(this).attr("selfId");
            var title = $(this).attr("name");
            var mark = scoreObj["mark"][fuId+"."+childId];
            if(mark){
                $ui.modalMarkInit({"id":"#myModalBox","mark":mark,"title":title});
                $("#myModalBox").find("#myModal").modal("show");
            }else{
                $bb.toastShow("无备注",1500);
            }
        })
    };
    return event;
});